package com.unet.disk.disk.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.unet.common.utils.Query;
import com.unet.disk.disk.dao.MemberDao;
import com.unet.disk.disk.entity.MemberEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.unet.common.utils.PageUtils;

import com.unet.disk.disk.dao.MemberNetdiskDao;
import com.unet.disk.disk.entity.MemberNetdiskEntity;
import com.unet.disk.disk.service.MemberNetdiskService;


@Service("memberNetdiskService")
public class MemberNetdiskServiceImpl extends ServiceImpl<MemberNetdiskDao, MemberNetdiskEntity> implements MemberNetdiskService {

    @Autowired
    private MemberNetdiskDao memberNetdiskDao;

    @Autowired
    private MemberDao memberDao;


    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<MemberNetdiskEntity> page = this.page(
                new Query<MemberNetdiskEntity>().getPage(params),
                new QueryWrapper<MemberNetdiskEntity>()
        );

        return new PageUtils(page);
    }


    @Override
    public List<MemberNetdiskEntity> findByUser(Long memberId) {
        MemberNetdiskEntity netdiskEntity = baseMapper.selectById(memberId);
        QueryWrapper<MemberNetdiskEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("member_id",memberId);
        List<MemberNetdiskEntity> entities = baseMapper.selectList(wrapper);
        return entities;
    }

    /**
     * update u_member_netdisk set member_id=0 where id=10001
     * @param id 网盘id
     */
    @Override
    public void disBinding(Long id) {
        /*MemberNetdiskEntity memberNetdiskEntity = new MemberNetdiskEntity();
        memberNetdiskEntity.setMemberId(0L).setStatus(3).setOnlineStatus(2).setDeviceAddr("");
        UpdateWrapper<MemberNetdiskEntity> wrapper = new UpdateWrapper<>();
        wrapper.eq("id",id);
        this.baseMapper.update(memberNetdiskEntity,wrapper);*/
        memberNetdiskDao.disBinding(id);
    }



    @Override
    public void bindingUpdate(MemberNetdiskEntity memberNetdiskEntity) {
        this.baseMapper.updateById(memberNetdiskEntity);
    }

    @Override
    public void updateOnlyTwo(String device_name,String device_addr,Long id) {
        MemberNetdiskEntity memberNetdiskEntity = new MemberNetdiskEntity();
        memberNetdiskEntity.setDeviceName(device_name).setDeviceAddr(device_addr);
        this.baseMapper.update(memberNetdiskEntity,new UpdateWrapper<MemberNetdiskEntity>().eq("id",id));
    }

}